//
//  WSQBaseConfig.m
//  WSQOCTools
//
//  Created by 翁胜琼 on 2019/1/19.
//  Copyright © 2019 Dev John. All rights reserved.
//

#import "WSQBaseConfig.h"
#import "Macros.h"

@implementation WSQBaseConfig

+ (instancetype)shared
{
    static id baseConfig = nil;
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        baseConfig = [[super allocWithZone:NULL] init];
    });
    
    return baseConfig;
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
    return [self shared];
}


// MARK: - setter && getter
- (NSString *)privateKey
{
    return [DEFAULTS objectForKey:NSStringFromSelector(_cmd)];
}

- (void)setPrivateKey:(NSString *)privateKey
{
    [DEFAULTS setObject:privateKey forKey:NSStringFromSelector(@selector(privateKey))];
    [DEFAULTS synchronize];
}

- (NSString *)lastVersion
{
    return [DEFAULTS objectForKey:NSStringFromSelector(_cmd)];
}

- (void)setLastVersion:(NSString *)lastVersion
{
    [DEFAULTS setObject:lastVersion forKey:NSStringFromSelector(@selector(lastVersion))];
    [DEFAULTS synchronize];
}

- (NSString *)currentVersion
{
    NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion=infoDic[@"CFBundleShortVersionString"];
    return currentVersion;
}

- (NSString *)anonymousToken
{
    return [DEFAULTS objectForKey:NSStringFromSelector(_cmd)];
}

- (void)setAnonymousToken:(NSString *)anonymousToken
{
    [DEFAULTS setObject:anonymousToken forKey:NSStringFromSelector(@selector(anonymousToken))];
    [DEFAULTS synchronize];
}

- (BOOL)hasGuideViewVisited
{
    return [[DEFAULTS objectForKey:NSStringFromSelector(_cmd)] boolValue];
}

- (void)setHasGuideViewVisited:(BOOL)hasGuideViewVisited
{
    [DEFAULTS setBool:hasGuideViewVisited forKey:NSStringFromSelector(@selector(hasGuideViewVisited))];
    [DEFAULTS synchronize];
}

- (NSString *)accessToken
{
    return [DEFAULTS objectForKey:NSStringFromSelector(_cmd)];
}

- (void)setAccessToken:(NSString *)accessToken
{
    [DEFAULTS setObject:accessToken forKey:NSStringFromSelector(@selector(accessToken))];
    [DEFAULTS synchronize];
}
@end
